#include "RC.h"
#include "bsp_uart.h"

Remote_DataTypeDef RC_Data={0};
//yaw_ctrl 0不动 1左 2右
//ball_speed_ctrl 0不动 1- 2+

void RC_Init(Remote_DataTypeDef* RC,UART_HandleTypeDef* huart)
{
	RC->huart=huart;
	RC->ball_speed_ctrl=0;
	RC->yaw_ctrl=0;
	RC->cmd_gear=0;
    HAL_UART_Receive_IT(huart, (uint8_t*)data, 23);
}

void RC_Callback(Remote_DataTypeDef* RC,uint8_t* data,Rx_DataTypeDef* Rx_Buffer)
{
	RC->gear=data[1]-1;
	
	data[2]=Rx_Buffer->bytes[0];
	data[3]=Rx_Buffer->bytes[1];
	data[4]=Rx_Buffer->bytes[2];
	data[5]=Rx_Buffer->bytes[3];
	
	data[6]=Rx_Buffer->bytes[4];
	data[7]=Rx_Buffer->bytes[5];
	data[8]=Rx_Buffer->bytes[6];
	data[9]=Rx_Buffer->bytes[7];
	
	data[10]=Rx_Buffer->bytes[8];
	data[11]=Rx_Buffer->bytes[9];
	data[12]=Rx_Buffer->bytes[10];
	data[13]=Rx_Buffer->bytes[11];
	
	data[14]=Rx_Buffer->bytes[12];
	data[15]=Rx_Buffer->bytes[13];
	data[16]=Rx_Buffer->bytes[14];
	data[17]=Rx_Buffer->bytes[15];
	
	data[18]=Rx_Buffer->bytes[16];
	data[19]=Rx_Buffer->bytes[17];
	data[20]=Rx_Buffer->bytes[18];
	data[21]=Rx_Buffer->bytes[19];
	
	RC->X=Rx_Buffer->float_Buffer[0];
	RC->Y=Rx_Buffer->float_Buffer[1];
	RC->Yaw=Rx_Buffer->float_Buffer[2];
	RC->Extra_Speed=Rx_Buffer->float_Buffer[3];
	RC->Extra_Angle=Rx_Buffer->float_Buffer[4];
}

void RC_Send_Data(Remote_DataTypeDef* RC)
{
	uint8_t data[3]={0xAA,RC->cmd_gear,0xBB};
	HAL_UART_Transmit(RC->huart,(uint8_t*)data,sizeof(uint8_t)*3,500);
}